package co.edu.unal.bioingenium.kbmed.config;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;

/**
 *
 * @author Alejandro Riveros Cruz
 */
public class Configuration {

    /**
     * The language in which the KBMed system works
     */
    public static final String LANGUAGE;
    /**
     * The KBMed home directory
     */
    public static final String KBMED_HOME;
    /**
     * The KBMed data directory
     */
    public static final String DATA_DIR;
    /**
     * The KBMed index directory
     */
    public static final String INDEX_DIR;
    /**
     * The KBMed feature directory
     */
    public static final String FEATURE_DIR;
    /**
     * The KBMed feature directory
     */
    public static final String EXPERIMENTS_DIR;
    /**
     * The feature type that the system will be use
     */
    public static final String COLLECTION_NAME;
    /**
     * The feature type that the system will be use
     */
    public static final String COLLECTION_PATH;
    /**
     * The feature type that the system will be use
     */
    public static final String FEATURE_TYPE;
    /**
     * The feature type that the system will be use
     */
    public static final String QUERY_FEATURE_TYPE;
    /**
     * The similarity function that the system will be use
     */
    public static final String SIMILARITY_FUNCTION;
    /**
     * The similarity function that the system will be use
     */
    public static final String SEMANTIC_SIMILARITY_FUNCTION;
    /**
     * The knowledge source name
     */
    public static final String KNOWLEDGE_SOURCE_NAME;
    /**
     * The knowledge source name
     */
    public static final String KNOWLEDGE_SOURCE_METADATA_CLASS_NAME;
    /**
     * The IP of the knowledge source database server
     */
    public static final String KNOWLEDGE_SOURCE_DB_SERVER_IP;
    /**
     * The name of the database in which the knowledge source are loaded
     */
    public static final String KNOWLEDGE_SOURCE_DB_NAME;
    /**
     * The username to connect with the knowledge source database
     */
    public static final String KNOWLEDGE_SOURCE_DB_USER;
    /**
     * The password to connect with the knowledge source database
     */
    public static final String KNOWLEDGE_SOURCE_DB_PASS;
    /**
     * 
     */
    public static final String MAPPING_SERVICE_ENDPOINT;
    /**
     * 
     */
    public static final String KNOWLEDGE_SOURCE_SERVICE_ENDPOINT;
    /**
     * 
     */
    public static final String INDEX_SERVICE_ENDPOINT;
    /**
     * 
     */
    public static final String RETRIEVAL_SERVICE_ENDPOINT;
    /**
     * 
     */
    public static final int FEATURE_ALL_TO_1 = 1;
    /**
     * 
     */
    public static final int FEATURE_FREQUENCY = 2;
    /**
     * 
     */
    public static final int FEATURE_RELATIVE_FREQUENCY = 3;
    /**
     * 
     */
    public static final int FEATURE_TF_IDF = 4;

    static {
        File directory;
        ResourceBundle bundle = PropertyResourceBundle.getBundle("KBMedConfig");
        LANGUAGE = bundle.getString("language");
        KBMED_HOME = bundle.getString("kbmedHome");
        directory = new File(KBMED_HOME);
        if (!directory.exists()) {
            directory.mkdir();
        }
        directory = null;
        DATA_DIR = KBMED_HOME + File.separator + "data";
        directory = new File(DATA_DIR);
        if (!directory.exists()) {
            directory.mkdir();
        }
        directory = null;
        INDEX_DIR = KBMED_HOME + File.separator + "index";
        directory = new File(INDEX_DIR);
        if (!directory.exists()) {
            directory.mkdir();
        }
        directory = null;
        FEATURE_DIR = KBMED_HOME + File.separator + "features";
        directory = new File(FEATURE_DIR);
        if (!directory.exists()) {
            directory.mkdir();
        }
        directory = null;
        EXPERIMENTS_DIR = KBMED_HOME + File.separator + "experiments";
        directory = new File(EXPERIMENTS_DIR);
        if (!directory.exists()) {
            directory.mkdir();
        }
        directory = null;
        COLLECTION_NAME = bundle.getString("collectionName");
        COLLECTION_PATH = bundle.getString("collectionPath");
        FEATURE_TYPE = bundle.getString("featureType");
        QUERY_FEATURE_TYPE = bundle.getString("queryFeatureType");
        SIMILARITY_FUNCTION = bundle.getString("similarityFunction");
        SEMANTIC_SIMILARITY_FUNCTION = bundle.getString("semanticSimilarityFunction");
        KNOWLEDGE_SOURCE_NAME = bundle.getString("knowledgeSourceName");
        KNOWLEDGE_SOURCE_METADATA_CLASS_NAME = bundle.getString("knowledgeSourceMetaDataClass");
        KNOWLEDGE_SOURCE_DB_SERVER_IP = bundle.getString("DBServerIp");
        KNOWLEDGE_SOURCE_DB_NAME = bundle.getString("DBName");
        KNOWLEDGE_SOURCE_DB_USER = bundle.getString("DBUserName");
        KNOWLEDGE_SOURCE_DB_PASS = bundle.getString("DBPass");
        MAPPING_SERVICE_ENDPOINT = bundle.getString("mappingServiceEndpoint");
        KNOWLEDGE_SOURCE_SERVICE_ENDPOINT = bundle.getString("knowledgeSourceServiceEndpoint");
        INDEX_SERVICE_ENDPOINT = bundle.getString("indexServiceEndpoint");
        RETRIEVAL_SERVICE_ENDPOINT = bundle.getString("retrievalServiceEndpoint");
        try {
            LogManager.getLogManager().readConfiguration(new FileInputStream(KBMED_HOME + File.separator + "logging.properties"));
        } catch (IOException ex) {
            Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SecurityException ex) {
            Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, null, ex);
        }
        Logger.getLogger(Configuration.class.getName()).log(Level.CONFIG, "LANGUAGE: {0}", LANGUAGE);
        Logger.getLogger(Configuration.class.getName()).log(Level.CONFIG, "KBMED_HOME: {0}", KBMED_HOME);
        Logger.getLogger(Configuration.class.getName()).log(Level.CONFIG, "DATA_DIR: {0}", DATA_DIR);
        Logger.getLogger(Configuration.class.getName()).log(Level.CONFIG, "INDEX_DIR: {0}", INDEX_DIR);
        Logger.getLogger(Configuration.class.getName()).log(Level.CONFIG, "COLLECTION_NAME: {0}", COLLECTION_NAME);
        Logger.getLogger(Configuration.class.getName()).log(Level.CONFIG, "COLLECTION_PATH: {0}", COLLECTION_PATH);
        Logger.getLogger(Configuration.class.getName()).log(Level.CONFIG, "FEATURE_DIR: {0}", FEATURE_DIR);
        Logger.getLogger(Configuration.class.getName()).log(Level.CONFIG, "EXPERIMENTS_DIR: {0}", EXPERIMENTS_DIR);
        Logger.getLogger(Configuration.class.getName()).log(Level.CONFIG, "FEATURE_TYPE: {0}", FEATURE_TYPE);
        Logger.getLogger(Configuration.class.getName()).log(Level.CONFIG, "QUERY_FEATURE_TYPE: {0}", QUERY_FEATURE_TYPE);
        Logger.getLogger(Configuration.class.getName()).log(Level.CONFIG, "SIMILARITY_FUNCTION: {0}", SIMILARITY_FUNCTION);
        Logger.getLogger(Configuration.class.getName()).log(Level.CONFIG, "SEMANTIC_SIMILARITY_FUNCTION: {0}", SEMANTIC_SIMILARITY_FUNCTION);
        Logger.getLogger(Configuration.class.getName()).log(Level.CONFIG, "KNOWLEDGE_SOURCE_NAME: {0}", KNOWLEDGE_SOURCE_NAME);
        Logger.getLogger(Configuration.class.getName()).log(Level.CONFIG, "KNOWLEDGE_SOURCE_METADATA_CLASS_NAME: {0}", KNOWLEDGE_SOURCE_METADATA_CLASS_NAME);
        Logger.getLogger(Configuration.class.getName()).log(Level.CONFIG, "KNOWLEDGE_SOURCE_DB_SERVER_IP: {0}", KNOWLEDGE_SOURCE_DB_SERVER_IP);
        Logger.getLogger(Configuration.class.getName()).log(Level.CONFIG, "KNOWLEDGE_SOURCE_DB_NAME: {0}", KNOWLEDGE_SOURCE_DB_NAME);
        Logger.getLogger(Configuration.class.getName()).log(Level.CONFIG, "MAPPING_SERVICE_ENDPOINT: {0}", MAPPING_SERVICE_ENDPOINT);
        Logger.getLogger(Configuration.class.getName()).log(Level.CONFIG, "KNOWLEDGE_SOURCE_SERVICE_ENDPOINT: {0}", KNOWLEDGE_SOURCE_SERVICE_ENDPOINT);
        Logger.getLogger(Configuration.class.getName()).log(Level.CONFIG, "INDEX_SERVICE_ENDPOINT: {0}", INDEX_SERVICE_ENDPOINT);
        Logger.getLogger(Configuration.class.getName()).log(Level.CONFIG, "RETRIEVAL_SERVICE_ENDPOINT: {0}", RETRIEVAL_SERVICE_ENDPOINT);
    }
}
